package org.hnxxxy.ebms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.hnxxxy.ebms.common.Result;
import org.hnxxxy.ebms.mapper.TeacherAdmissMapper;
import org.hnxxxy.ebms.pojo.RecruitStu;
import org.hnxxxy.ebms.mapper.RecruitStuMapper;
import org.hnxxxy.ebms.pojo.Role;
import org.hnxxxy.ebms.pojo.Teacher;
import org.hnxxxy.ebms.service.RecruitStuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.hnxxxy.ebms.service.RoleService;
import org.hnxxxy.ebms.service.TeacherAdmissService;
import org.hnxxxy.ebms.service.TeacherService;
import org.hnxxxy.ebms.util.CommonUntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WANGWEI
 * @since 2021-06-10
 */
@Service
public class RecruitStuServiceImpl extends ServiceImpl<RecruitStuMapper, RecruitStu> implements RecruitStuService {


    @Autowired
    private RoleService roleService;

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private TeacherAdmissMapper teacherAdmissMapper;

    @Autowired
    private RecruitStuMapper recruitStuMapper;


    @Override
    public Result<String> add(RecruitStu recruitStu) {
        this.save(recruitStu);
        return Result.success(200,"添加成功");
    }

    @Override
    public Result<IPage<RecruitStu>> getRecStusByName(String name,int page) {
        // 通过角色id查询到角色表
        Integer id = CommonUntil.getId();
        Role role = roleService.getById(id);
        // 通过用户id，查询到地区id，通过地区id查询到学生
        List<Integer> aId = teacherAdmissMapper.selectByTeaId(role.getUserId());
        IPage<RecruitStu> recruitStuPage = new Page<>(page, 10);
        IPage<RecruitStu> iPage = recruitStuMapper.selectByAdmissIdAndNamePage(recruitStuPage, aId,name);
        return Result.success(iPage);
    }

    @Override
    public Result<IPage<RecruitStu>> getRecStus(int page) {
        // 通过角色id查询到角色表
        Integer id = CommonUntil.getId();
        Role role = roleService.getById(id);
        // 通过用户id，查询到地区id，通过地区id查询到学生
        List<Integer> aId = teacherAdmissMapper.selectByTeaId(role.getUserId());
        IPage<RecruitStu> recruitStuPage = new Page<>(page, 10);
        IPage<RecruitStu> iPage = recruitStuMapper.selectByAdmissIdPage(recruitStuPage, aId);
        return Result.success(iPage);
    }
}
